package com.yuanqiworld.vw.web;

import com.yuanqiworld.vw.domain.Device;
import com.yuanqiworld.vw.domain.Metadata;
import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/devices")
@Controller
@RooWebScaffold(path = "devices", formBackingObject = Device.class)
@RooWebJson(jsonObject = Device.class)
public class DeviceController {

    void populateEditForm(Model uiModel, Device device) {
        uiModel.addAttribute("device", device);
        uiModel.addAttribute("devicePositions", Metadata.findSortedMetadatasByCategory("DEVICE_POSITION").getResultList());
        uiModel.addAttribute("deviceTypes", Metadata.findSortedMetadatasByCategory("DEVICE_TYPE").getResultList());
    }
}
